import * as React from 'react';
import { Point, Range } from '../../reducer/const';
import { COLOR } from './Style';
import { PathString } from '../../util/eventUtil';

import StartNode from './StartNode';


export default class ErrorNode extends StartNode {

    constructor(props: any) {
        super(props);
        const {history} = this.props;
        if (history) {
            this.colorStroke = COLOR.stroke2;
            this.colorIcon = COLOR.fill1;
            this.colorFill = COLOR.err1;
            this.strokeWidth = 0;
            this.strokeIconWidth = 3;
        } else {
            this.colorStroke = COLOR.stroke1;
            this.colorIcon = COLOR.err2;
            this.colorFill = COLOR.fill1;
            this.strokeWidth = 1;
            this.strokeIconWidth = 3;
        }
    }

    getRefs = () => {
        return this.refs;
    }

    getIconAttr() {
        const iconAttr = { 'stroke': `${this.colorIcon}`, 'fill': `none`, 'stroke-width': `${5}` };
        return iconAttr;
    }

    getIconPath(range: Range) {
        const size = range.width * 0.3;
        const point: Point = new Point(range.x + range.width / 2, range.y + range.height / 2);
        const pointA: Point = new Point(range.x + size, range.y + size);
        const pointB: Point = new Point(range.x + size, range.y + range.height - size);
        const pointC: Point = new Point(range.x + range.width - size, range.y + range.height - size);
        const pointD: Point = new Point(range.x + range.width - size, range.y + size);

        return new PathString().M(pointA).L(pointC).L(point).L(pointB).L(pointD).toString();
    }

}
